export const handleSubMsgIds = item => {
  wx.getSetting({
    withSubscriptions: true,
    success(res) {
      console.log(res)
      if (res.subscriptionsSetting.mainSwitch) { // 用户打开了订阅消息总开关
        if (res.subscriptionsSetting.itemSettings) { // 用户同意总是保持是否推送消息的选择, 这里表示以后不会再拉起推送消息的授权
          const resAry = []
          item.forEach(ele => {
            const moIdState = res.subscriptionsSetting.itemSettings[ele];
            resAry.push({
              id: ele,
              moIdState: moIdState
            })
          });
          // 找出拒绝的二次弹出确认
          const idsAry =  resAry.filter(data => data.moIdState == 'reject' || !data.moIdState)
        
          if(idsAry.length > 0) {
            const ids = idsAry.map(itm => itm.id)
            wx.requestSubscribeMessage({
              tmplIds: ids,
              success(res) {
                console.log(res)
              },
              fail (error){
                console.log(error)
              }        
            })
          }
        } else {
          wx.requestSubscribeMessage({
            tmplIds: item,
            success(res) {
              console.log(res)
            },
            fail (error){
              console.log(error)
            }
          })
        }
      } else {
        wx.showModal({
          title: '温馨提示',
          content: '您已拒绝任务消息,将收取不到申请结果信息，是否需要打开开关？',
          confirmText:"打开",
          cancelText: "返回",
          showCancel:false,
          success: function (res) {
            if (res.confirm) {
              wx.openSetting({
                withSubscriptions: true,
              }) 
            } else {

            }      
          }
        })
        
      }
    }
  })
}